<?php
include_once '../header1.php';
?>
</head>
<body>
<?php
include_once ("$basedir"."/Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("$basedir"."/index.php");
}
   else
   {
   if(!isset($_POST['Register']))
	{
	$maxid=mysql_query("SELECT max(	Competition_Id) as maxId FROM competitions");

while($rowid=mysql_fetch_array($maxid))
{
$m_Id=$rowid['maxId'];
$inum=substr("$m_Id",1);
$inn=($inum+1);
//$r=(strlen($inum)-strlen($inn));
$Competition_Id='C';
if(strlen($inn)<strlen($inum))
{
for($i=0;$i<(strlen($inum)-strlen($inn));$i++)
{
$Competition_Id=$Competition_Id.'0';
}
$Competition_Id=$Competition_Id.$inn;
}
else
{
$Competition_Id=$Competition_Id.$inn;
}
}

	}
if(isset($_POST['Register']))
	   { 
	   $Competition_Id=$_POST['Competition_Id'];
	   
	   if($Competition_Id!="")
	   {
$Com_Che=mysql_query("SELECT * FROM Competitions WHERE Competition_Id='$Competition_Id'");
if($rowc=mysql_fetch_array($Com_Che))
		{
			$_SESSION['errorexi']="Sorry this Competition's record already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Administrator")
   {
	   require_once 'REGcomp.php';
	   }
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
}
}

}
	
?>
<?php
include_once "../header2.php";
?><?php
include_once "topmenu.php";
?>
<?php
  		if(isset($_POST['Register']))
{
  $result=mysql_query("SELECT * FROM competitions");
  if(mysql_num_rows($result)>=12)
  {
  
echo '<div class="lefts">';
 echo '<div class="articles">';
}
else
{
echo '<div class="left">';
 echo '<div class="article">';
}
  }
  else
{
echo '<div class="left">';
 echo '<div class="article">';
}
  ?>
  
  <form action="#" method="POST">
  <br/>
    <br/>
  <table width="518" height="108" border="0" class="tablefont" >
    <tr>
      <th height="23" colspan="4"  scope="row"><?php
		if(isset($_POST['Register']))
{
	if(isset($_SESSION['errorin']))
	{
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errorexi']))
	{
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
	}
	
}
		?></th>
      
    </tr>
    <tr>
      <th width="29" rowspan="10"  scope="row">&nbsp;</th>
      <th width="159" height="25"  scope="row">
        
        
       Competition Id:</th>
  
	   <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Competition_Id' value='$Competition_Id'/>";
echo '</td>';

}
else
{
echo '<td>';
if(isset($Competition_Id))
{
echo "<input type='text' name='Competition_Id' value='$Competition_Id' readonly='readonly'/>";
}
else
{
echo "<input type='text' name='Competition_Id'/>";
}

echo '</td>';

}?>
      <td width="316" rowspan="2">
      <?php
		if(isset($_POST['Register']))
{
      if(isset($_SESSION['errornotallo']))
	{
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
}
?></td>
      </tr>
    
    <tr>
      <th height="25" scope="row">Competition Name:</th>
       <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Competition_Name' value='$Competition_Name'/>";
echo '</td>';

}
else
{
echo '<td >';
echo "<input type='text' name='Competition_Name'/>";
echo '</td>';

}?>
      </tr>
    <tr>
      <th height="25" scope="row">&nbsp;</th>
      
	   
   <td width="316"><?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['OK']))
{
$result=mysql_query("SELECT * FROM competitions");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {

echo '<table width="330" border="1" class="righttable" >
<tr background="../images/img0991.jpg">
<td width="140"><font color="#000000">Competition Id</font></td>
<td width="190"><font color="#000000">Competition Name</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
  $Com_Id=$_SESSION['Competition_Id'];
   if($row['Competition_Id']=="$Com_Id")
  {
    echo '<tr bgcolor="#936">';
    echo '<td width="140"><font color="#000000">'.$row['Competition_Id'].'</font></td>';
     echo '<td width="190"><font color="#000000">'.$row['Competition_Name'].'</font></td>';
    echo '</tr>';
  unset($_SESSION['Competition_Id']);
  }
 else
  {
    echo '<tr>';
    echo '<td width="140">'.$row['Competition_Id'].'</td>';
    echo '<td width="190">'.$row['Competition_Name'].'</td>';
    echo '</tr>';
  }
  }
   echo "</table>";

  }
  unset($_SESSION['OK']);
  }
  }
  
  ?></td>
      </tr>
     </table>
  <br/>
   <?php
  if(!isset($_POST['Register']))
{
   echo '<a href="RegCompetition.php" class="reset">Reset |</a>';
   echo '<input name="Register" align="middle" type="submit" value="Register" />';
   }
    if(isset($_POST['Register']))
{
 $Competition_Id=$_POST['Competition_Id'];
 $Competition_Name=$_POST['Competition_Name'];
  if($Competition_Id==""||$Competition_Name=="")
  {
  echo '<a href="RegCompetition.php" class="reset">Reset |</a>';
   echo '<input name="Register" align="middle" type="submit" value="Register" />';
  }
  }
   ?>
 </form>
</div>
</div>

<?php
 if(isset($_POST['Register']))
{
  $result=mysql_query("SELECT * FROM competitions");
  if(mysql_num_rows($result)>=12)
  {
  
echo '<div class="rightmenus"> ';

}
else
{
echo '<div class="rightmenu"> ';

}
}
else
{
echo '<div class="rightmenu"> ';

}
  
  ?>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>

<?php

	}
?>
</body>
</html>